/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.managed;

import beans.ejb.NflplayerFacade;
import beans.ejb.NflplayerseasonstatFacade;
import customEneities.JoinPlayerStats;
import entities.Nflplayer;
import entities.Nflplayerseasonstat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author The Lunatics
 */
@ManagedBean(eager=true, name = "nflPlayerList")
@ApplicationScoped
public class NflplayerListBean {

    @EJB
    private NflplayerseasonstatFacade nflplayerseasonstatFacade;
    @EJB
    private NflplayerFacade nflplayerFacade;
    private List<Nflplayer> players;
    private List<Nflplayer> playersShort;

    public List<Nflplayer> getPlayersShort() {
        if (playersShort==null) {
            playersShort = nflplayerFacade.findRange(range);
        }
        return playersShort;
    }

    public void setPlayersShort(List<Nflplayer> playersShort) {
        this.playersShort = playersShort;
    }
    private List<Nflplayerseasonstat> seasonStats;

    private List<JoinPlayerStats> mergedList = new ArrayList<JoinPlayerStats>();
    private int[] range = {1, 50};

    public List<Nflplayer> getPlayers() {
        if (players == null) {
//            long prev = System.currentTimeMillis();
            players = nflplayerFacade.findAll();
//            long time = System.currentTimeMillis() - prev;
//            System.err.print("End Query:  " + time);
        }
        return players;
    }

    public void setPlayers(List<Nflplayer> players) {
        this.players = players;
    }

    public List<Nflplayerseasonstat> getSeasonStats() {
        if (seasonStats == null) {
//            long prev = System.currentTimeMillis();
            seasonStats = nflplayerseasonstatFacade.findAll();
//            long time = System.currentTimeMillis() - prev;
//            System.err.print("End Query:  " + time);
        }
        return seasonStats;
    }
    
    public void setSeasonStats(List<Nflplayerseasonstat> seasonStats) {
        this.seasonStats = seasonStats;
    }

//    public List<JoinPlayerStats> getMergedList() {
//        //getPlayers();
//        //getSeasonStats();
//        //List<Nflplayerseasonstat> seasonStats = nflplayerseasonstatFacade.findRange(range);
//        List<Nflplayer> players = nflplayerFacade.findRange(range);
//        HashMap<Integer,Nflplayer> map = new HashMap<Integer, Nflplayer>();
////        for (Iterator<Nflplayerseasonstat> it = seasonStats.iterator(); it.hasNext();) {
////            Nflplayerseasonstat seasonStat = it.next();
////            map.put(seasonStat.getNflplayerseasonstatPK().getPlayerId(), seasonStat);
////        }
//
//        for (Iterator<Nflplayerseasonstat> it = seasonStats.iterator(); it.hasNext();) {
//            Nflplayerseasonstat seasonStat = it.next();
//            JoinPlayerStats row = new JoinPlayerStats(seasonStat.getNflplayerseasonstatPK(), season);
//        }
//
//        return mergedList;
//    }
//
//    public void setMergedList(List<JoinPlayerStats> mergedList) {
//        this.mergedList = mergedList;
//    }
    /**
     * Creates a new instance of NflplayerListBean
     */
    public NflplayerListBean() {
    }
}
